charset="UTF-8"
Ext.onReady(function(){
	Ext.QuickTips.init();
     // example of custom renderer function
    function change(val){
        if(val > 0){
            return '<span style="color:green;">' + val + '</span>';
        }else if(val < 0){
            return '<span style="color:red;">' + val + '</span>';
        }
        return val;
    }

    // example of custom renderer function
    function pctChange(val){
        if(val > 0){
            return '<span style="color:green;">' + val + '%</span>';
        }else if(val < 0){
            return '<span style="color:red;">' + val + '%</span>';
        }
        return val;
    }
    
 

    //查询医生工作表面板
    var queryDoctorWorkTimeForm = new Ext.FormPanel({
        labelAlign: 'top',
        frame:true,
        title: '查询条件',
        bodyStyle:'padding:5px 5px 0',
        width:780,
        collapsible: true,//最小化
        items:[
        	{layout:'column',border:false,labelSeparator:':',
             defaults:{layout: 'form',border:false,columnWidth:.25},
              items:[
                    {items: [{
							xtype:'datefield',
                    		fieldLabel: '预约日期',
                    		id:'querysignday',
                    		name: 'signday',
                    		emptyText:'请选择日期', 
                    		invalidText : "{0} 是无效的日期 - 必须符合格式： {1}", 
							format : "Y-m-d" , 
							minValue:new Date(),  
          					minText:'时间不能早于今天',
          					showToday:false,
                    		anchor:'90%'
                    }]}
               ]}
               ],
		monitorValid:true,
		
        buttons: [{
            text: '查询',
            formBind: true,
            handler:function(){       
            	doctorWorkTimeStore.baseParams = {
        			signday:queryDoctorWorkTimeForm.getForm().findField('signday').getValue()
        		},
                doctorWorkTimeStore.reload({params:{start:0,limit:15}});
                }
        },{
            text: '重置',
            handler:function(){
					queryDoctorWorkTimeForm.form.reset();
					doctorWorkTimeStore.removeAll();
                }
        }]
    });
    

    
	
  
var doctorWorkTimeRecord = Ext.data.Record.create([
				{name:'id'},  
              {name:'doctorName'},
              {name:'doctorTitle'},  
              {name:'departmentName'}, 
              {name:'hospitalName'}, 
              {name:'time'}, 
              {name:'workdate',type : 'date', dateFormat : 'm-d-Y'},
              {name:'maxpatientnum'}, 
              {name:'nowpatientnum'}
		]);
    // create the data store
    var doctorWorkTimeStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({  
                	url:"queryWorkTimeByPageDoctor.action",  
                    method:"post"  
                }),  
        reader : new Ext.data.JsonReader({
        	totalProperty : 'totalProperty',
        	root : 'workTimeVOList'
        	 }, 
        	 doctorWorkTimeRecord
        	 )
    });

	 var sm = new Ext.grid.CheckboxSelectionModel();  
	 
    var column = new Ext.grid.ColumnModel({
    		columns:[
    		new Ext.grid.RowNumberer(),
    		sm,
            {
            	header: "值班编号", 
            	width: 70, 
            	sortable: true, 
            	dataIndex: 'id'
            },
            {
            	header: "值班日期", 
            	width: 120,
            	sortable: true,
            	renderer: Ext.util.Format.dateRenderer('Y/m/d'), 
            	dataIndex: 'workdate'
            },
            {
            	header: "值班时间", 
            	width: 80,
            	sortable: true,
            	dataIndex: 'time'
            },
            {
            	header: "最大预约人数", 
            	width: 100,
            	dataIndex: 'maxpatientnum'
            },
            {
            	header: "当前预约人数", 
            	width: 100,
            	dataIndex: 'nowpatientnum'
            }
        ]});
        column.defaultSortable = true;//默认可排序  


        
    // create the Grid
    var doctorWorkTimeGrid = new Ext.grid.GridPanel({
        id:'doctorWorkTime-grid',
        store: doctorWorkTimeStore,
        cm: column,
        sm: sm,
        height:400,
        width:780,
        title:'值班信息列表',
		loadMask: {msg:'正在加载数据，请稍侯……'},
		collapsible: true,//最小化
        plugins: new Ext.ux.PanelResizer({
            minHeight: 100
        }),
       
       tbar: [{
        	ref: '../addBtn',
            iconCls: 'icon-add',
            text: '添加值班时间段',
            handler: function(){
            	addWorkTimeWindow.show();
            }
        }],
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: doctorWorkTimeStore,
            displayInfo: true,
			displayMsg:'显示第 {0} 条到 {1} 条记录，一共 {2} 条',  
            emptyMsg:'没有记录',
            plugins: new Ext.ux.ProgressBarPager()
        })
    });

        var jobTimeRecord = Ext.data.Record.create([
				{name:'id'},  
              {name:'time'}
		]);
    // create the data store
    var jobTimeStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({  
                	url:"queryJobTimeByPageDoctor.action",  
                    method:"post"  
                }),  
        reader : new Ext.data.JsonReader({
        	totalProperty : 'totalProperty',
        	root : 'jobTimeVOList'
        	 }, 
        	 jobTimeRecord
        	 )
    });
   
   //添加值班表表单
   var addWorkTimeForm = new Ext.FormPanel({
        labelAlign: 'top',
        frame:true,
        title: '值班信息',
        bodyStyle:'padding:5px 5px 0',
        width: 500,
        items:[
        	{layout:'column',border:false,labelSeparator:':',
        	
             defaults:{layout: 'form',border:false,columnWidth:.33},
              items:[
               
                    {items: [{
						xtype:"datefield",
						fieldLabel: '值班日期',
						allowBlank:false,
                    	blankText:'不能为空',
                    	emptyText:'请选择日期',
                    	invalidText : "{0} 是无效的日期 - 必须符合格式： {1}", 
						format : "Y-m-d" ,
						minValue:new Date(),  
          				minText:'时间不能早于今天',  
						name:"signDate",
						anchor:'90%'
					}]},
					 {items: [{
					xtype:"combo",
					name: "jobTime",
					store:jobTimeStore,
					mode:"remote",
					editable:false,
					pageSize: 15,
					displayField:"time",
					hiddenName: "jobTimeId",
					valueField:"id",
					triggerAction: 'all',
					fieldLabel:"值班时间",
					emptyText:"请选择值班时间",
					loadingText:"正在加载数据，请稍后。。。",
                    allowBlank:false,
                    blankText:'不能为空',
                    anchor:'90%'
                    
            	}]},
					{items: [{
						xtype:'numberfield',
						vtype:'integer',
                   		allowBlank:false,
                    	blankText:'不能为空',
                    	fieldLabel: '最大预约人数',
                    	name: 'maxPatientNum',
                    	anchor:'90%'
                    	}]}
               ]}
               ],
		monitorValid:true,
		
        buttons: [{
            text: '保存',
            formBind: true,
            handler:function(){                   
            	addWorkTimeForm.getForm().submit({//客户端的数据提交给服务器   
                     url:'addWorkTimeDoctor.action',      
                     method:'post',
                     waitTitle: '信息', 
                    waitMsg:"正在提交，请稍候。。。",  
                    success: function(form, action){   
                         Ext.MessageBox.alert('信息', '添加成功');
                         addWorkTimeForm.form.reset();
                 		 addWorkTimeWindow.hide();
                 		 doctorWorkTimeStore.reload();
                      },
                     failure:function(form, action){  
                         Ext.MessageBox.alert('错误', '添加失败，请重试'); 
                         addWorkTimeForm.form.reset();
                 		 addWorkTimeWindow.hide();
                     }                                  
                 }); 
            	
          
            }
            	
            	
            
        },{
            text: '取消',
            handler:function(){
					addWorkTimeForm.form.reset();
                    addWorkTimeWindow.hide();
                }
        }]
    });
	//添加值班窗体
    var addWorkTimeWindow = new Ext.Window({
	title : '添加值班',
	width : 518,
	height : 160,
	plain : true,
	closeAction : 'hide',// 关闭窗口
	maximizable : false,// 最大化控制 值为true时可以最大化窗体
	layout:'Form',
	items : [addWorkTimeForm]
});
   


   doctorWorkTimeGrid.render('worktimeGrid');
   queryDoctorWorkTimeForm.render('queryPanel');
   

   
});